package com.woniuxy.service.impl;

import com.github.pagehelper.PageInfo;
import com.woniuxy.commons.utils.ResStatus;
import com.woniuxy.commons.utils.ResponseResult;
import com.woniuxy.dao.PrescriptionOrderDao;
import com.woniuxy.entity.MedicineOrder;
import com.woniuxy.entity.PrescriptionOrder;
import com.woniuxy.entity.RegisteredOrder;
import com.woniuxy.service.PrescriptionOrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PrescriptionOrderServiceImpl implements PrescriptionOrderService {
    @Resource
    PrescriptionOrderDao prescriptionOrderDao;
    @Override
    public ResponseResult findAll(int currentPage, int pageSize) {
        List<PrescriptionOrder> list = prescriptionOrderDao.findAll();
        PageInfo<PrescriptionOrder> pageInfo = PageInfo.of(list);
        ResponseResult responseResult = new ResponseResult<>();

        responseResult.setData(pageInfo);

        responseResult.setCode(200);

        responseResult.setMsg("查询成功");

        responseResult.setStatus(ResStatus.SUCCESS);
        return responseResult;
    }

    @Override
    public ResponseResult search(PrescriptionOrder prescriptionOrder) {
        List<PrescriptionOrder> list=prescriptionOrderDao.search(prescriptionOrder);

        ResponseResult responseResult = new ResponseResult<>();

        responseResult.setCode(200);

        responseResult.setMsg("查询成功");

        responseResult.setStatus(ResStatus.SUCCESS);

        responseResult.setData(list);
        return responseResult;
    }

    @Override
    public ResponseResult updateOne(PrescriptionOrder prescriptionOrder) {
        int i=prescriptionOrderDao.update(prescriptionOrder);
        if(i>0){
            return  ResponseResult.SUCCESS;
        }
        return ResponseResult.Fail;
    }

    @Override
    public ResponseResult deleteOne(int id) {
        int i=prescriptionOrderDao.delete(id);
        if (i > 0) {
            return  ResponseResult.SUCCESS;
        }
        return ResponseResult.Fail;
    }


}
